package top.sdwu_top.kbase.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.sdwu_top.kbase.common.annocation.CurrentUser;
import top.sdwu_top.kbase.common.model.Wrapper;
import top.sdwu_top.kbase.entity.KbaseAuthRole;
import top.sdwu_top.kbase.entity.KbaseAuthUser;
import top.sdwu_top.kbase.service.IKbaseAuthRoleService;
import top.sdwu_top.kbase.vo.KbaseAuthRoleVo;

import java.util.List;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author zhipeng.duan@nvr-china.com
 * @since 2020-02-20
 */
@RestController
@RequestMapping("api/auth-role")
public class KbaseAuthRoleController {

    @Autowired
    IKbaseAuthRoleService authRoleService;

    @PostMapping
    public Wrapper<String> create(@RequestBody KbaseAuthRole authRole) {
        if (authRoleService.save(authRole)) {
            return Wrapper.ok("角色新建成功");
        }
        return Wrapper.error("角色新建失败");
    }

    @PutMapping
    public Wrapper<String> update(@RequestBody KbaseAuthRole authRole) {
        if (authRoleService.updateById(authRole)) {
            return Wrapper.ok("角色修改成功");
        }
        return Wrapper.error("角色修改失败");
    }

    @DeleteMapping("{id}")
    public Wrapper<String> delete(@PathVariable String id) {
        if (authRoleService.delete(id)) {
            return Wrapper.ok("删除成功");
        }
        return Wrapper.error("删除失败");
    }

    @PostMapping("page")
    public Wrapper<Page<KbaseAuthRole>> page(KbaseAuthRoleVo authRoleVo) {
        return Wrapper.ok(authRoleService.page(authRoleVo));
    }

    @GetMapping("list")
    public Wrapper<List<KbaseAuthRole>> list(@CurrentUser KbaseAuthUser user) {
        return Wrapper.ok(authRoleService.getRoleList(user));
    }

}

